;;;; Created on 2008-06-27 21:39:09

(in-package :cl-user)

(load
 (merge-pathnames
  (make-pathname
   :directory '(:relative ".")
   :name "jacolib-init" :type "lisp" :case :local)
  (make-pathname 
   :directory (pathname-directory *load-truename*)
   :host (pathname-host *load-truename*)
   :device (pathname-device *load-truename*))))

;
; user' s parameters 
;

(defparameter default-port 40013)
(defparameter default-password "bella")

;
; *jacolib-args*
;

#+clisp
(defvar *jacolib-args* ext:*args*)
#+sbcl
(defvar *jacolib-args* (rest sb-ext:*posix-argv*))
#+cmu
(defvar *jacolib-args* (cdr (cdr (cdr extensions:*command-line-strings*))))
#-(or clisp sbcl cmu)
(defvar *jacolib-args* nil)

;
; *jacolib-args*
;

(defvar *port* default-port)
(defvar *secret-string* default-password)
(defvar *ump* nil)

(if (> (length *jacolib-args*) 0)
    (progn    
      (setf *port* (parse-integer (first *jacolib-args*)))
      (setf *secret-string* (second *jacolib-args*))))
      
#+sbcl 
 (setf *ump* t)
#+cmu
 (setf *ump* t)

      
;
; start the server
;

(setf (cl-log:log-manager) (make-instance 'cl-log:log-manager 
                                          :message-class 'cl-log:formatted-message))
(cl-log:start-messenger 'cl-log:text-file-messenger 
                        :filename "./jacolib-log.txt"
                        :category '(or :protocol-error :protocol-info
                                       :authentication-error :authentication-info))

(defvar *jacolib* (make-instance 'jacolib:jacolib))

(format t "launch jacolib server with arguments: ~A ~A ~A~%" *port* *secret-string* *ump*)
(jacolib:jacolib-start-server *jacolib* "sh" *port* *secret-string* *ump*)
